//
//  HJGroupManagerApprovalCell.m
//  KaiChat
//
//  Created by lx on 2023/11/14.
//

#import "HJGroupManagerApprovalCell.h"

@interface HJGroupManagerApprovalCell()

@property (nonatomic, weak) UISwitch *switchView;
@property (nonatomic, weak) UILabel *titleLabel;
@property (nonatomic, weak) UILabel *subTextLabel;

@end


@implementation HJGroupManagerApprovalCell

- (void)settingSubView {
    [super settingSubView];
    
    self.selectionStyle = UITableViewCellSelectionStyleNone;

    UILabel *titleLabel = [UILabel lableWithSuperView:self.contentView font:UIFontMediumMake(14) color:UIColor.tj_333333Color title:nil textAlignment:NSTextAlignmentLeft];
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(20);
        make.left.offset(leftRightMargin);
    }];
    
    UILabel *subTextLabel = [UILabel lableWithSuperView:self.contentView font:UIFontMake(12) color:UIColor.tj_868391Color title:nil textAlignment:NSTextAlignmentLeft];
    subTextLabel.numberOfLines = 0;
    [subTextLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(titleLabel.mas_bottom).offset(9);
        make.left.equalTo(titleLabel);
        make.right.inset(leftRightMargin);
    }];
    
    
    _switchView = [UISwitch addToView:self.contentView];
    _switchView.onTintColor = UIColor.tj_mainColor;
    [_switchView addTarget:self action:@selector(switchValueDidChange:) forControlEvents:UIControlEventValueChanged];
    _switchView.transform = CGAffineTransformMakeScale(0.85, 0.85);
    [_switchView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.inset(leftRightMargin);
        make.centerY.equalTo(titleLabel);
    }];
    
    _titleLabel = titleLabel;
    _subTextLabel = subTextLabel;
}

- (void)switchValueDidChange:(UISwitch *)switchView {
    if (_switchValueChange) {
        _switchValueChange(switchView);
    }
}


- (void)setModel:(HJCellModel *)model {
    _model = model;
    
    _titleLabel.text = model.text;
    _switchView.on = model.isOn;
    _subTextLabel.attributedText = [model.subText titleMargin:2 alignment:NSTextAlignmentLeft];

}

@end
